﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoadHousingDialog.aspx.cs"
    Inherits="ZLDC.Estate.SM.LoadHousingDialog" %>

<%@ Register src="../UserControl/Estate_Autocomplete5.ascx" tagname="Estate_Autocomplete5" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>同步到新系统</title>
    <base target="_self"></base>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align: center;">
        <b>选择新系统中对应的房号</b>
    </div>
    <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                <font color="red">楼盘名称</font>
            </td>
            <td bgcolor="#F7F7F7">
                
                <uc1:Estate_Autocomplete5 ID="Estate_Autocomplete51" runat="server" />
                
            </td>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                <font color="red">栋阁 </font>
            </td>
            <td bgcolor="#F7F7F7">
                <select id="buildName1" name="buildName1" style="width: 75px" onchange="loadparentBuild()"
                    class="textstyle1">
                    <option></option>
                </select><select id="buildName2" name="buildName2" onchange="loadparentBuild3()"
                    class="textstyle1" style="width: 65px">
                    <option></option>
                </select><select id="buildName3" name="buildName3" onchange="loadparentBuildName()"
                    class="textstyle1" style="width: 65px">
                    <option></option>
                </select>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                <font color="red">房号</font>
            </td>
            <td bgcolor="#F7F7F7">
                <input id="roomNo" name="roomNo" type="text" title="点击右侧图标取回房号" class="textstyle1"
                    style="width: 50px;" onblur="isChn();" />&nbsp;<a href="javascript:roomNoDialog();"
                        style="cursor: pointer;">取房号</a>
            </td>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                城区|片区
            </td>
            <td bgcolor="#F7F7F7">
                <select id="dname" name="dname" style="width: 50px;" class="textstyle1">
                </select>
                <select id="area" name="area" style="width: 50px;" class="textstyle1">
                </select>
            </td>
        </tr>
    </table>
    <div id="tabbottom" style="text-align: center;">
        <input id="btnSave" type="button" value="确定" class="button_bak" onclick="return submitOk()" />
        &nbsp;&nbsp;
        <input id="btnClose" type="button" value="关闭" class="button_bak" onclick="window.close();" />
    </div>
    <font color="red">注意：如找不到对应的房号，请先申请房号</font>
    <input id="houseType" readonly name="houseType" type="hidden" />
    <input id="dname1" name="dname1" type="hidden" />
    <input id="area1" name="area1" type="hidden" />
    <input id="bname1" name="bname1" type="hidden" />
    <input id="bname2" name="bname2" type="hidden" />
    <input id="bname3" name="bname3" type="hidden" />
    <input id="floor" name="floor" type="hidden" />
    <input id="roomid" name="roomid" value="0" type="hidden" />
    </form>

    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../js/jquery.autocomplete.js" type="text/javascript"></script>

    <script src="../js/LexunJS.js" type="text/javascript"></script>

    <script type="text/javascript">

        function loadparentBuild() {
            var id = LexunJS.GetSelectValue("buildName1");
            document.getElementById("bname1").value = LexunJS.GetSelectText("buildName1");

            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerIndex.ashx',
                data: 'act=SelectNamesByBId&id=' + id,
                timeout: '20000',
                error: function() {
                    alert("系统繁忙，请稍候后试！");
                },
                success: function(json) {
                    SelectNameByParent(json);
                }
            });
        }

        // 加载城市列表回调
        function SelectNameByParent(response) {
            var json = eval("(" + response + ")");
            var record = json.record;

            document.getElementById("buildName2").options.length = 0;
            document.getElementById("buildName3").options.length = 0;

            $("#buildName2").html("");
            var obj = document.getElementById("buildName2");

            LexunJS.selectAddOption(obj, "请选择", 0);

            if (record == null || record.length == 0) return;

            var recordLength = record.length;
            for (var i = 0; i < recordLength; i++) {
                var sName = record[i].name;
                var sValue = record[i].id;

                LexunJS.selectAddOption(obj, sName, sValue);
            }
        }

        function loadparentBuild3() {
            var id = LexunJS.GetSelectValue("buildName2");
            document.getElementById("bname2").value = LexunJS.GetSelectText("buildName2");

            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerIndex.ashx',
                data: 'act=SelectNamesByBId&id=' + id,
                timeout: '20000',
                error: function() {
                    alert("编缉失败！");
                },
                success: function(json) {
                    SelectNameByParent3(json);
                }
            });
        }

        // 加载城市列表回调
        function SelectNameByParent3(response) {
            var json = eval("(" + response + ")");
            var record = json.record;

            document.getElementById("buildName3").options.length = 0;

            $("#buildName3").html("");
            var obj = document.getElementById("buildName3");

            LexunJS.selectAddOption(obj, "请选择", 0);

            if (record == null || record.length == 0) return;

            var recordLength = record.length;
            for (var i = 0; i < recordLength; i++) {
                var sName = record[i].name;
                var sValue = record[i].id;

                LexunJS.selectAddOption(obj, sName, sValue);
            }
        }

        function loadparentBuildName() {
            document.getElementById("bname3").value = LexunJS.GetSelectText("buildName3");
        }

        //弹出窗口,取返回值
        function roomNoDialog() {
            var ename = document.getElementById("iEstateName").value;
            var bname2 = document.getElementById("bname2").value;
            var bname3 = document.getElementById("bname3").value;
            var id = document.getElementById("buildName1").value;
            if (bname2.length > 0) {
                id = document.getElementById("buildName2").value;
            }
            if (bname3.length > 0) {
                id = document.getElementById("buildName3").value;

            }

            if (id == 0 || id == "") {
                alert("请选择栋阁！");
                return;
            }

            //弹出房号列表
            var path = "../TM/ShowRooms.aspx?id=" + id;
            var parameter = "";
            var style = "dialogWidth:638px; dialogHeight:563px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
            var arr = window.showModalDialog(path, parameter, style);

            if (typeof (arr) == "undefined" || arr == null) {

                return;
            }
            var str = new Array();
            str = arr.split(',');
            document.getElementById("roomNo").value = ""; // 清空房号，ID
            document.getElementById("roomid").value = "";
            document.getElementById("floor").value = "";


            document.getElementById("roomNo").value = str[0];
            document.getElementById("roomid").value = str[1];
            document.getElementById("floor").value = str[2];
        }

        //验证房间号，不能输入中文
        function isChn() {
            var str = document.getElementById("roomNo");
            if (str.value != "整层") {
                var reg = /^[A-Za-z0-9-+]+$/;
                if (!reg.test(str.value) && str.value != "") {
                    alert("请输入数字,字母,以及-,+，整层(-为多套连通房源用，+为双拼房源时用，请大家严格遵守)");
                    str.value = "";
                    str.focus();
                    return false;
                }
            }
        }

        // 提交同步
        function submitOk() {
            var bname1 = document.getElementById("iEstateName").value;
            if (bname1 == "") {
                alert("请输入楼盘名称!");
                return false;
            }
            var bname = LexunJS.GetSelectText("buildName1");
            if (bname == "请选择") {
                alert("请选择栋阁！");
                return false;
            } else {
                if (bname.length = 0 || bname.replace(/(^\s*)|(\s*$)/g, "") == "") {
                    alert("请选择栋阁！");
                    return false;
                }
            }
            var roomno = document.getElementById("roomNo").value;
            if (roomno == "") {
                alert("请选择房间号！");
                return false;
            }

            var roomid = document.getElementById("roomid").value;
            if (parseInt(roomid) <= 0) {
                alert("请选择正确的房间号！");
                return false;
            }

            var id = LexunJS.GetQueryString("id"); // 盘源ID

            $("#btnSave").attr("disabled", "true");
            $("#btnSave").attr("value", "正在提交...");

            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerLoad.ashx',
                data: 'act=loadhousing_save&id=' + id + '&roomid=' + roomid,
                timeout: '20000',
                error: function() {
                    alert("同步失败！");
                    $("#btnSave").removeAttr("disabled");
                    $("#btnSave").attr("value", "提交");
                },
                success: function(outmsg) {
                    $("#btnSave").removeAttr("disabled");
                    $("#btnSave").attr("value", "提交");
                    alert(outmsg);
                    window.close();
                }
            });
        }
        
    </script>

</body>
</html>
